package rezetkaPages;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import utils.ReportWriter;

import java.util.NoSuchElementException;

/**
 * Created by IIGalytska on 10.04.14.
 */
public class ResultPage extends BasePage{

    public ResultPage(WebDriver driver) {
        super(driver);
    }

    public String getFirstLink(){
        try {

            if (driver.findElement(firstLinkToSearchresult).isDisplayed()){
             ReportWriter.info("Link to the search item was found");
            }
        }catch (NoSuchElementException ex){
            ReportWriter.info("Link to the search item was not found");
        }
            return driver.findElement(firstLinkToSearchresult).getText();

    };

    public CartWindow pressBuyForFirstLink(){

        WebDriverWait wait = new WebDriverWait(driver, 10);
        wait.until(ExpectedConditions.elementToBeClickable(By.name("topurchasesfromcatalog")));
        driver.findElement(By.name("topurchasesfromcatalog")).click();

        return new CartWindow(driver);
    }





}
